package com.kerraway.config.sharding;

import com.kerraway.dao.OrderRepository;
import org.springframework.stereotype.Component;

/**
 * 该工厂类用于解决 {@link OrderLogShardingAlgorithm} 无法注入 Spring Bean 的问题
 *
 * @author 小柯
 * @date 2019/07/18
 */
@Component
@Deprecated
public class OrderDaoFactory {

  private static OrderRepository orderDao;

  public OrderDaoFactory(OrderRepository orderDao) {
    OrderDaoFactory.orderDao = orderDao;
  }

  public static OrderRepository orderDao() {
    if (orderDao == null) {
      throw new IllegalStateException("orderDao is not initialized yet.");
    }
    return orderDao;
  }

}
